/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Utilities.TrainingUtilities;
import com.sun.lwuit.Button;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import com.sun.lwuit.plaf.Style;
import javax.wireless.messaging.Message;
import testmenu.MainMidlet;

/**
 *
 * @author Huy
 */
public class TrainedForm extends View {

    private ComboBox cbx_training;
    private final TextField txt_time;
    private final Label lbl_time;
    private final Button btn_Submit;
    private final Command cmd_back;

    public TrainedForm(final MainMidlet midlet) {
        super(midlet);

        Label lbl_training = new Label("Hôm nay tôi đã : ");
        addComponent(lbl_training);

        cbx_training = new ComboBox();
        cbx_training.addItem("Đi bộ");
        cbx_training.addItem("Chạy bộ");
        cbx_training.addItem("Đạp xe");
        addComponent(cbx_training);

        lbl_time = new Label("Thời gian hoạt động(Phút): ");
        txt_time = new TextField();
        txt_time.setConstraint(TextField.NUMERIC);
        btn_Submit = new Button("OK");
        btn_Submit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                try {
                    int time = Integer.parseInt(txt_time.getText());
                    int c = cbx_training.getSelectedIndex();
                    double MET = 0;
                    switch (c) {
                        case 0:
                            MET = 2.3;
                            break;
                        case 1:
                            MET = 2.9;
                            break;
                        case 2:
                            MET = 4.0;
                            break;
                    }
                    TrainingUtilities u = new TrainingUtilities();
                    double cb = u.calc_CalorieBurn(midlet.getVar_BMR(), MET, time);
                    Dialog.show("Thông tin", "Hôm nay bạn đã " + cbx_training.getSelectedItem() + " trong " + time + "phút \n Năng lượng bạn đã tiêu thụ trong ngày : \n" + cb + " calo", "OK", null);
                } catch (NumberFormatException ex) {
                    Dialog.show("Lỗi", "Lỗi định dạng !", "OK", null);
                }
            }
        });


        addComponent(lbl_time);
        addComponent(txt_time);
        
        
        addComponent(btn_Submit);
        cmd_back = new Command("") {
            public void actionPerformed(ActionEvent evt) {

                Display.getInstance().setForceFullScreen(true);
                midlet.getmmf().showBack();
            }
        };

        setBackCommand(cmd_back);
    }
}
